﻿package cn.poco.pepsi.service.impl;

import java.io.InputStream;
import java.util.List;

import android.util.Log;
import cn.poco.pepsi.bean.Discount;
import cn.poco.pepsi.service.IDiscount;
import cn.poco.pepsi.util.UrlConnectionUtil;
import cn.poco.pepsi.util.UrlMatchUtil;
import cn.poco.pepsi.util.xmlpared.DisCountDetailXmlparse;
import cn.poco.pepsi.util.xmlpared.DiscountXmlparse;



public class DiscountImpl implements IDiscount {

	@Override
	public List<Discount> getAllDiscount(String type, String cd, int l, int s) throws Exception {
		System.out.println("开始获取。。。。。");
//		t l s 
		String urlString=GET_DIS.replace("#a", type).replace("#b", String.valueOf(s)).replace("#c", String.valueOf(l));
		
		//cd 城市ID（可选，只在类型为全部优惠时使用）
		if (cd!=null) {
			urlString=urlString+"&cd="+cd; 
		}
		urlString=UrlMatchUtil.matchUrl(urlString);
		Log.i("impl", urlString);
		InputStream inputStream=UrlConnectionUtil.getRequest(urlString);
		return DiscountXmlparse.getXml(inputStream);
		
	}

	@Override
	public Discount getDiscountByResId(String resId) throws Exception {
		String urlString=GET_DISBYRESID.replace("#a", resId);
		urlString=UrlMatchUtil.matchUrl(urlString);
		Log.i("impl", urlString);
		InputStream inputStream=UrlConnectionUtil.getRequest(urlString);
		return DisCountDetailXmlparse.getXml(inputStream);
	}

}
